#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>

int main()
{
	int ADCval;
	ADMUX = (1<<REFS0)|(1<<ADLAR);	//5V reference and left justified
	ADCSRA = (1<<ADEN);				//Enable ADC
	ADCSRB = 0x00;					//Free running mode
	DDRB = 0xFF;					//make PORTB output
	
	while(1)
	{
		ADMUX = (ADMUX & 0xF0)|(0 & 0x0F);	//ADC0
		ADCSRA |= 1<<ADSC;					//Convert
		while(ADCSRA & (1<<ADSC));			//Wait until finished
		ADCval = ADC>>6;					//Shift right 6 to use converted value
		
		PORTB = PORTB | (1<<1);				//Motor is off
		_delay_ms(10);						//for 10ms
		PORTB = PORTB & (~(1<<1));			//Motor is on
		for (int i = 0; i<ADCval; i+=10)
		{
			_delay_ms(10);
		}
	}
	return 0 ;
}